package cn.jingzhuan.element.demo.view

import android.content.Context
import android.content.Intent
import android.support.v4.app.Fragment
import cn.jingzhuan.element.element.R

open class BaseFragment: Fragment() {

    fun getBaseActivity(): BaseActivity {
        return activity as BaseActivity
    }

    fun isAttachedToActivity(): Boolean {
        return !isRemoving
    }

    protected val SLIDE_TRANSITION_CONFIG = TransitionConfig(
            R.anim.slide_in_right, R.anim.slide_out_left,
            R.anim.slide_in_left, R.anim.slide_out_right)

    protected val SCALE_TRANSITION_CONFIG = TransitionConfig(
            R.anim.scale_enter, R.anim.slide_still,
            R.anim.slide_still, R.anim.scale_exit)

    /**
     * 转场动画控制
     */
    fun onFetchTransitionConfig(): TransitionConfig {
        return SLIDE_TRANSITION_CONFIG
    }

    ////////界面跳转动画
    class TransitionConfig(val enter: Int, val exit: Int, val popenter: Int, val popout: Int) {
        constructor(enter: Int, popout: Int) : this(enter, 0, 0, popout) {}
    }

    companion object {
        fun openActivity(context: Context?, activityCla : Class<out BaseActivity>,title:String) {
            val intent = Intent(context, activityCla)
            intent.putExtra("title",title)
            context?.startActivity(intent)
        }
    }
}